package com.bnyy.medicalHousekeeper.moudle.message.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.SizeUtils;
import com.bnyy.medicalHousekeeper.R;
import com.bnyy.medicalHousekeeper.base.BaseActivityImpl;
import com.bnyy.medicalHousekeeper.moudle.message.adapter.NoticeGoodsAdapter;
import com.bnyy.message.bean.chat.ChatMessage;
import com.bnyy.message.bean.chat.message_data.NoticeGoodsMessage;
import com.bnyy.message.event.ReceiveMessageEvent;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.function.Consumer;

import butterknife.BindView;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2023/1/9
 **/
public class NoticeGoodsActivity extends BaseActivityImpl {
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.iv_no_data)
    ImageView ivNoData;
    @BindView(R.id.tv_no_data)
    TextView tvNoData;
    @BindView(R.id.ll_no_data)
    LinearLayout llNoData;

    private NoticeGoodsAdapter adapter;

    @Override
    public boolean registerEventBus() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.layout_recycler_view;
    }

    @Override
    public String getTitleStr() {
        return "服务通知";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
//        adapter = new NoticeGoodsAdapter(mContext, new Consumer<ChatMessage>() {
//            @Override
//            public void accept(ChatMessage chatMessage) {
//               NoticeGoodsMessage noticeGoodsMessage = (NoticeGoodsMessage) chatMessage.getMessageData();
//
//               if (noticeGoodsMessage != null) {
//                   switch (noticeGoodsMessage.getGoodsType()) {
//                       case UNKNOWN:
//                           break;
//                       case NORMAL:
//                       case GROUP_PURCHASE:
//                           show(mContext, MallGoodsOrderListActivity.class);
//                           break;
//                       case SERVICE:
//                           ServiceGoodsOrderDetailActivity.show(mContext, noticeGoodsMessage.getId());
//                           break;
//                   }
//               }
//            }
//        });
//        recyclerView.setAdapter(adapter);
//        int padding = SizeUtils.dp2px(12);
//        recyclerView.setPadding(padding, 0, padding, padding);
//        ArrayList<ChatMessage> noticeAlarmMessages = MessageManager.getNoticeGoodsMessages();
//        if (noticeAlarmMessages.size() > 0) {
//            adapter.refresh(noticeAlarmMessages);
//        } else {
//            llNoData.setVisibility(View.VISIBLE);
//        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(ReceiveMessageEvent event) {

        switch (event.getMessageType()) {
            case NOTICE_GOODS:
                ChatMessage chatMessage = (ChatMessage) event.getMessage();
                adapter.insert(chatMessage, 0);
                llNoData.setVisibility(View.GONE);
                break;
        }
    }
}

































